<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="单据编号" prop="code">
        <el-input
          v-model="queryParams.code"
          placeholder="请输入单据编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="单据阶段" prop="docStage">
        <el-input
          v-model="queryParams.docStage"
          placeholder="请输入单据阶段"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="caigouxunjiaList"
              highlight-current-row
              @current-change="handleCurrentChange">
<!--      <el-table-column type="selection" width="55" align="center"/>-->

      <el-table-column label="主键id" align="center" prop="id"/>
      <el-table-column label="单据编号" align="center" prop="code" width="180" fixed/>
      <el-table-column label="源单编号" align="center" prop="sourceCode" width="180" fixed/>
      <el-table-column label="单据日期" align="center" prop="docDate" width="180"/>
      <el-table-column label="单据阶段" align="center" prop="docStage"/>
      <el-table-column label="审批结果" align="center" prop="approvalResult"/>
      <el-table-column label="是否生效" align="center" prop="isEffect"/>
      <el-table-column label="是否关闭" align="center" prop="isClose"/>
      <el-table-column label="是否作废" align="center" prop="isCancel"/>
      <el-table-column label="创建时间" align="center" prop="createDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="修改人" align="center" prop="modifyBy"/>
      <el-table-column label="修改时间" align="center" prop="modifyDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.modifyDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
import {
  listCaigouxunjia,
  getCaigouxunjia,
  getCaigouxunjiaInfo,
  delCaigouxunjia,
  addCaigouxunjia,
  updateCaigouxunjia, addCaigouxunjiaPlus
} from "@/api/caigou/caigouxunjia";


import {getBuyReqPlus, getGoodsListByBuyReqIds, getInfoListByIds} from "@/api/caigou/buyReq";

export default {
  name: "Caigouxunjia",
  components: {},
  data() {
    return {
      currentRow:null,
      activeName: 't1',
      // 遮罩层
      loading: true,


      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 采购询价表格数据
      caigouxunjiaList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        code: null,
        docStage: null,
        approvalResult: null,
        isEffect: null,
        isClose: null,
        isCancel: null,
        createDate: null,
        modifyBy: null,
        modifyDate: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        modifyBy: [
          {required: true, message: "修改人不能为空", trigger: "change"}
        ],
      }
    };
  },
  watch: {
    buyReqList: {
      handler(newVal, oldVal) {
        console.log(newVal)
        if (newVal.length > 0) {
          this.formOpr = 4
        } else {
          this.formOpr = 1
        }
      },
      deep: true
    }
  },
  created() {
    this.getList();
  },
  methods: {
    handleCurrentChange(val){
      this.currentRow = val;
    },
    returnBuyAsk(){
      return this.currentRow;
    },
    /** 查询采购询价列表 */
    getList() {
      this.loading = true;
      listCaigouxunjia(this.queryParams).then(response => {
        this.caigouxunjiaList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        code: null,
        docStage: null,
        approvalResult: null,
        isEffect: null,
        isClose: null,
        isCancel: null,
        createBy: null,
        createDate: null,
        modifyBy: null,
        modifyDate: null,
        isDel: null,
        docDate: null
      };
      this.resetForm("form");


      //被选中的采购申请商品数组
      this.selectBuyReqGoodsList = [];
      //采购申请的商品列表
      this.buyReqGoodsList = [],
      //采购申请
      this.buyReqList = [],

      // 采购申请的商品的id 数量 对应数组
      this.idAndNumberArr = [],
      // 询价商品数组
      this.goodsArr = [];
      // 选中数组
      this.buyReqSelectListIds = [];
      this.ids = [];

    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },

  }
};
</script>
